#include "cschdatacollector.h"
#include "cjgorder.h"
#include "cjgorderprocess.h"

CSchDataCollector::CSchDataCollector() {}

CJgBoxData * CSchDataCollector::FindBoxByNum(SSCHDATAINPUT * lpIn, QString vBoxNum)
{
    CJgBoxData *pF = nullptr;
    for (QVector<CJgOrder *> vOrderOneGroup : lpIn->OrderGroupByDeadLine)
    {
        //1.0、循环每个货期里面的订单
        for (CJgOrder * vOrder : vOrderOneGroup)
        {
            //2.0、循环每个部件
            for (QVector<CJgBoxData *> pBoxs : vOrder->mCurBoxSetGroupByPart)
            {
                //3.0、循环每个筐
                for (CJgBoxData * pBox : pBoxs)
                {
                    if (pBox->mBoxNum == vBoxNum)
                    {
                        pF = pBox;
                        break;
                    }
                }
                if (pF)break;
            }
            if (pF)break;
        }
        if (pF)break;
    }

    return pF;
}

CJgOrderProcess * CSchDataCollector::FindProcessByOrderPartSeq(SSCHDATAINPUT * lpIn, CJgBoxData * pBox)
{
    CJgOrderProcess * pRet = nullptr;
    //qDebug() << pBox->mLocalOrderNum << "--" << pBox->mBoxNum << "--" << pBox->miPartSeqNum;
    //0.0循环每个货期
    for (QVector<CJgOrder *> vOrderOneGroup : lpIn->OrderGroupByDeadLine)
    {
        //1.0、循环每个货期里面的订单
        for (CJgOrder * vOrder : vOrderOneGroup)
        {
            if (vOrder->mLocalOrderNum == pBox->mLocalOrderNum)
            {
                if (vOrder->mOrderProcessSetGroupByPart.count(pBox->mPartName))
                {
                    //2.0、循环部件
                    QVector< CJgOrderProcess *> processes = vOrder->mOrderProcessSetGroupByPart[pBox->mPartName];
                    for (CJgOrderProcess * process : processes)
                    {
                        if (process->miPartSeqNum == pBox->miPartSeqNum)
                        {
                            pRet = process;
                            break;
                        }
                    }
                }
                //break;
            }
            if (nullptr != pRet)
            {
                break;
            }
        }
        if (nullptr != pRet)
        {
            break;
        }
    }
    return pRet;
}

CJgOrderProcess * CSchDataCollector::findOrderProcess(SSCHDATAINPUT * vp, qlonglong vOrderProcess)
{
    QMap<QString /*部件名*/, QVector<CJgOrderProcess *>>::const_iterator iter2;
    QVector <QVector<CJgOrder *>>::const_iterator itvr;
    QVector<CJgOrder *>::const_iterator itr;
    QVector<CJgOrderProcess *>::const_iterator iter3;
    for (itvr = vp->OrderGroupByDeadLine.constBegin(); itvr != vp->OrderGroupByDeadLine.constEnd(); ++itvr)
    {
        for (itr = itvr->constBegin(); itr != itvr->constEnd(); ++itr)
        {
            CJgOrder * vOrder = *itr;
            for (iter2 = vOrder->mOrderProcessSetGroupByPart.constBegin(); iter2 != vOrder->mOrderProcessSetGroupByPart.constEnd(); ++iter2)
            {
                for (iter3 = iter2.value().constBegin(); iter3 != iter2.value().constEnd(); ++iter3)
                {
                    CJgOrderProcess * pOp = *iter3;
                    if (pOp->miProcessId == vOrderProcess)
                    {
                        return pOp;
                    }
                }
            }
        }
    }
    return nullptr;
}
